<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>售后记录查询</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="售后记录查询"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'projectName',width:120,align:'center'">项目名称</th>
				<th data-options="field:'productName',width:120,align:'center'">产品名称</th>
				<th data-options="field:'cusName',width:100,align:'center'">客户</th>
				<th data-options="field:'customerName',width:100,align:'center'">客户名称</th>
				<th data-options="field:'contactPerson',width:60,align:'center'">联系人</th>
				<th data-options="field:'contactPersonTel',width:80,align:'center'">联系方式</th>
				<th data-options="field:'outOfWarrantySign',width:60,align:'center'">是否过保</th>
				<th data-options="field:'registerTime',width:100,align:'center'">登记日期</th>
				<th data-options="field:'expectFinishDate',width:100,align:'center'">期望完成日期</th>
				<th data-options="field:'status',width:40,align:'center'">状态</th>
				<th data-options="field:'id',width:80,align:'center',formatter:formatControl">查看</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			项目名称:
			<select id = "project" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projects }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			关联产品:
			<select id = "product" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${products }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			客户名称:
			<select id = "customer" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${customers }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			处理类型:
			<select id = "aftersaleHandleType" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${aftersaleHandleTypes }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			登记人:
			<select id = "registerPerson" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${persons }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			处理人:
			<select id = "handlePerson" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${persons }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			审核人:
			<select id = "checkPerson" class="easyui-combobox" data-options="editable: false">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${persons }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			登记日期: <input class="easyui-datebox" type="text" id="registerTimeBegin" style="width:100px;height:25px;">
			~ <input class="easyui-datebox" type="text" id="registerTimeEnd" style="width:100px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="售后记录详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:1100px; height:450px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
						<tr>
							<td width="200px;" align="right">项目名称：</td>
							<td width="160px">
								<select id="lookProjectId" class="easyui-combobox" data-options="required:true" disabled="disabled">
									<c:forEach var="item" items="${projects }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="130px;" align="right">关联产品：</td>
							<td>
								<select id="lookProductId" class="easyui-combobox" data-options="required:true" disabled="disabled">
									<c:forEach var="item" items="${products }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="160px;"  align="right">状态：</td>
							<td>
								<input class="easyui-textbox" id="lookStatus" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td width="130px;" align="right">登记人：</td>
							<td width="160px">
								<select id="lookRegisterPersonId" class="easyui-combobox" data-options="required:true" disabled="disabled">
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">是否过保：</td>
							<td>
								<input class="easyui-textbox" id="lookOutOfWarrantySign" data-options="required:true" readonly="readonly" />
							</td>
							<td align="right">登记日期：</td>
							<td>
								<input class="easyui-datebox" id="lookRegisterTime" data-options="required:true" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">产品序列号：</td>
							<td>
								<input class="easyui-textbox" id="lookProductSequenceNo" data-options="required:true" readonly="readonly" />
							</td>
							<td align="right">联系人：</td>
							<td>
								<input class="easyui-textbox" id="lookContactPerson" data-options="required:true" readonly="readonly" />
							</td>
							<td align="right">联系方式：</td>
							<td>
								<input class="easyui-textbox" id="lookContactPersonTel" data-options="required:true" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td width="200px;" align="right">问题描述：</td>
							<td colspan="5">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 890px; height: 80px;" id="lookIssueDescription" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td align="right">期望完成日期：</td>
							<td>
								<input class="easyui-datebox" id="lookExpectFinishDate" data-options="required:true" readonly="readonly" />
							</td>
							<td width="130px;" align="right">客户：</td>
							<td width="160px">
								<select id="lookCusId" class="easyui-combobox" data-options="required:true" disabled="disabled">
									<c:forEach var="item" items="${customers }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">客户名称：</td>
							<td>
								<input class="easyui-textbox" id="lookCustomerName" data-options="required:true" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td width="130px;" align="right">处理人：</td>
							<td>
								<select id="lookHandlePersonId" class="easyui-combobox" disabled="disabled">
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="130px;" align="right">处理类型：</td>
							<td>
								<select id="lookAftersaleHandleTypeId" class="easyui-combobox" disabled="disabled">
									<c:forEach var="item" items="${aftersaleHandleTypes }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">返修日期：</td>
							<td>
								<input class="easyui-datebox" id="lookReturnDate" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">问题原因：</td>
							<td colspan="5">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 890px; height: 80px;" id="lookIssueReason" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td align="right">处理描述：</td>
							<td colspan="5">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 890px; height: 80px;" id="lookHandleDescription" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td align="right" rowspan="2">维修成本说明：</td>
							<td colspan="3" rowspan="2">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 450px; height: 80px;" id="lookHandleCostDescription" readonly="readonly">
							</td>
							<td align="right">维修费用：</td>
							<td>
								<input class="easyui-textbox" id="lookHandleFee" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">维修成本：</td>
							<td>
								<input class="easyui-textbox" id="lookHandleCost" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td width="130px;" align="right">审核人：</td>
							<td width="160px">
								<select id="lookCheckPersonId" class="easyui-combobox" disabled="disabled">
									<c:forEach var="item" items="${persons }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">审核日期：</td>
							<td>
								<input class="easyui-datebox" id="lookCheckTime" readonly="readonly" />
							</td>
							<td align="right">实际完成日期：</td>
							<td>
								<input class="easyui-datebox" id="lookActualFinishTime" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">售后处理工时：</td>
							<td>
								<input class="easyui-textbox" id="lookConsumeWorktime" readonly="readonly" />
							</td>
							<td align="right">修好日期：</td>
							<td>
								<input class="easyui-datebox" id="lookFinishDate" readonly="readonly" />
							</td>
							<td align="right">交付日期：</td>
							<td>
								<input class="easyui-datebox" id="lookDeliveryDate" readonly="readonly" />
							</td>
						</tr>
						<tr>
							<td align="right">备注：</td>
							<td colspan="5">
								<input class="easyui-textbox" data-options="multiline:true" style="width: 890px; height: 80px;" id="lookRemark" readonly="readonly">
							</td>
						</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + row.registerPersonId + ', ' + row.projectId + ', ' + row.productId + ', ' + row.cusId + ', ' + row.handlePersonId + ', ' + row.aftersaleHandleTypeId + ', ' + row.checkPersonId + ', \'' + row.issueDescription + '\', \'' + row.outOfWarrantySign + '\', \'' + row.registerTime + '\', \'' + row.expectFinishDate + '\', \'' + row.customerName + '\', \'' + row.contactPerson + '\', \'' + row.contactPersonTel + '\', \'' + row.status + '\', \'' + row.actualFinishTime + '\', \'' + row.consumeWorktime + '\', \'' + row.productSequenceNo + '\', \'' + row.checkTime + '\', \'' + row.returnDate + '\', \'' + row.finishDate + '\', \'' + row.deliveryDate + '\', \'' + row.issueReason + '\', \'' + row.handleDescription + '\', \'' + row.handleCostDescription + '\', ' + row.handleFee + ', ' + row.handleCost + ', \'' + row.remark + '\')">基本信息</a>';
		}
		function search(){
			var dg = $("#dg");
			var project = $("#project").combobox("getValue");
			var product = $("#product").combobox("getValue");
			var customer = $("#customer").combobox("getValue");
			var aftersaleHandleType = $("#aftersaleHandleType").combobox("getValue");
			var register = $("#registerPerson").combobox("getValue");
			var handlePerson = $("#handlePerson").combobox("getValue");
			var checkPerson = $("#checkPerson").combobox("getValue");
			var registerTimeBegin = $("#registerTimeBegin").textbox("getValue").trim();
			var registerTimeEnd = $("#registerTimeEnd").textbox("getValue").trim();
			var url = "queryAftersaleRecord?projectId=" + project + "&productId=" + product + "&customerId=" + customer + "&aftersaleHandleTypeId=" + aftersaleHandleType + "&handlePersonId=" + handlePerson + "&checkPerson=" + checkPerson + "&registerTimeBegin=" + registerTimeBegin + "&registerTimeEnd=" + registerTimeEnd + "&registerPersonId=" + register;
			dg.datagrid('reload', url);
		}
		function lookDetail(registerPersonId, projectId, productId, cusId, handlePersonId, aftersaleHandleTypeId, checkPersonId, issueDescription, outOfWarrantySign, registerTime, expectFinishDate, customerName, contactPerson, contactPersonTel, status, actualFinishTime, consumeWorktime, productSequenceNo, checkTime, returnDate, finishDate, deliveryDate, issueReason, handleDescription, handleCostDescription, handleFee, handleCost, remark){
			$("#lookRegisterPersonId").combobox("setValue", registerPersonId);
			$("#lookProjectId").combobox("setValue", projectId);
			$("#lookProductId").combobox("setValue", productId);
			$("#lookCusId").combobox("setValue", cusId);
			$("#lookHandlePersonId").combobox("setValue", handlePersonId);
			$("#lookAftersaleHandleTypeId").combobox("setValue", aftersaleHandleTypeId);
			$("#lookCheckPersonId").combobox("setValue", checkPersonId);
			$("#lookIssueDescription").textbox("setValue", issueDescription);
			$("#lookOutOfWarrantySign").textbox("setValue", outOfWarrantySign);
			$("#lookRegisterTime").textbox("setValue", registerTime);
			$("#lookExpectFinishDate").textbox("setValue", expectFinishDate);
			$("#lookCustomerName").textbox("setValue", customerName);
			$("#lookContactPerson").textbox("setValue", contactPerson);
			$("#lookContactPersonTel").textbox("setValue", contactPersonTel);
			$("#lookStatus").textbox("setValue", status);
			$("#lookActualFinishTime").textbox("setValue", actualFinishTime);
			$("#lookConsumeWorktime").textbox("setValue", consumeWorktime);
			$("#lookProductSequenceNo").textbox("setValue", productSequenceNo);
			$("#lookCheckTime").textbox("setValue", checkTime);
			$("#lookReturnDate").textbox("setValue", returnDate);
			$("#lookFinishDate").textbox("setValue", finishDate);
			$("#lookDeliveryDate").textbox("setValue", deliveryDate);
			$("#lookIssueReason").textbox("setValue", issueReason);
			$("#lookHandleDescription").textbox("setValue", handleDescription);
			$("#lookHandleCostDescription").textbox("setValue", handleCostDescription);
			$("#lookHandleFee").textbox("setValue", handleFee);
			$("#lookHandleCost").textbox("setValue", handleCost);
			$("#lookRemark").textbox("setValue", remark);
			
			$('#lookDetail').window('open');
		}
		function editItem(id, registerPersonId, projectId, productId, cusId, handlePersonId, aftersaleHandleTypeId, checkPersonId, issueDescription, outOfWarrantySign, registerTime, expectFinishDate, customerName, contactPerson, contactPersonTel, status, actualFinishTime, consumeWorktime, productSequenceNo, checkTime, returnDate, finishDate, deliveryDate, issueReason, handleDescription, handleCostDescription, handleFee, handleCost, remark){
			$("#editId").val(id);
			$("#editRegisterPersonId").combobox("setValue", registerPersonId);
			$("#editProjectId").combobox("setValue", projectId);
			$("#editProductId").combobox("setValue", productId);
			$("#editCusId").combobox("setValue", cusId);
			$("#editHandlePersonId").combobox("setValue", handlePersonId);
			$("#editAftersaleHandleTypeId").combobox("setValue", aftersaleHandleTypeId);
			$("#editCheckPersonId").combobox("setValue", checkPersonId);
			$("#editIssueDescription").textbox("setValue", issueDescription);
			$("#editOutOfWarrantySign").textbox("setValue", outOfWarrantySign);
			$("#editRegisterTime").textbox("setValue", registerTime);
			$("#editExpectFinishDate").textbox("setValue", expectFinishDate);
			$("#editCustomerName").textbox("setValue", customerName);
			$("#editContactPerson").textbox("setValue", contactPerson);
			$("#editContactPersonTel").textbox("setValue", contactPersonTel);
			$("#editStatus").textbox("setValue", status);
			$("#editActualFinishTime").textbox("setValue", actualFinishTime);
			$("#editConsumeWorktime").textbox("setValue", consumeWorktime);
			$("#editProductSequenceNo").textbox("setValue", productSequenceNo);
			$("#editCheckTime").textbox("setValue", checkTime);
			$("#editReturnDate").textbox("setValue", returnDate);
			$("#editFinishDate").textbox("setValue", finishDate);
			$("#editDeliveryDate").textbox("setValue", deliveryDate);
			$("#editIssueReason").textbox("setValue", issueReason);
			$("#editHandleDescription").textbox("setValue", handleDescription);
			$("#editHandleCostDescription").textbox("setValue", handleCostDescription);
			$("#editHandleFee").textbox("setValue", handleFee);
			$("#editHandleCost").textbox("setValue", handleCost);
			$("#editRemark").textbox("setValue", remark);
			
			$('#editItem').window('open');
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的售后记录吗？", function(r){
				if(r){
					data = "id=" + id;
					$.ajax({
					  type: "GET",
					  url: "delAftersaleRecord",
					  data: data,
					  success:function(data){
						  	var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '删除成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  }
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '添加成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '修改成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			//validateMenu
			search();//页面装载完成后加载数据
		});
	</script>
</body>
</html>